package com.moyun.common.freemarker;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;


/**
 * @Author yangboxuan
 * @Description freemarker demo
 * @Date 2022/3/29 14:58
 */

public class testFreemarker {
	public static void main(String[] args) throws Exception {

		String dir="D:/ybx/freemarker/";
		Configuration conf = new Configuration(Configuration.VERSION_2_3_28);
		//加载模板文件(模板的路径)
		conf.setDirectoryForTemplateLoading(new File(dir));
		// 加载模板
		Template template = conf.getTemplate("/freemarker-demo.ftl");
		// 定义数据
		
		Map root = new HashMap();
                root.put("world", "Hello World");
		// 定义输出
		Writer out = new FileWriter(dir + "/freemarker.java");
		template.process(root, out);
		System.out.println("转换成功");
		out.flush();
		out.close();
	}
}